package gui;

import gui.clock.AbstractClock;
import gui.clock.ClockDisplay;
import java.awt.Dimension;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JPanel;

public class UserControlPanel extends JPanel {
  private static final long serialVersionUID = -4563608487057327554L;
  private PhysicalControlPanel pnlPhysical;
  private SimulationControlPanel pnlSimulation;
  private InvocationSettingsPanel pnlInvocation;
  private QueryDateTimePanel pnlQueryDateTime;
  private QueryRegionPanel pnlQueryRegion;
  private QueryOutputSettingsPanel pnlQueryOutput;
  private QueryRunPanel pnlQueryRun;
  
  public UserControlPanel(EarthPanel pnlEarth, ClockDisplay clockDisplay) {
    super();
    
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    int pnlHeight = 300;
    setPreferredSize(new Dimension(100,pnlHeight));
    setMaximumSize(new Dimension(700,pnlHeight));
    
    pnlPhysical = new PhysicalControlPanel();
    pnlSimulation = new SimulationControlPanel(pnlEarth);
    pnlInvocation = new InvocationSettingsPanel();
    pnlQueryDateTime = new QueryDateTimePanel();
    pnlQueryRegion = new QueryRegionPanel();
    pnlQueryOutput = new QueryOutputSettingsPanel();
    pnlQueryRun = new QueryRunPanel(pnlEarth, this, clockDisplay);
    
    //row 1
    JPanel pnl = getRowPanel();
    pnl.add(pnlPhysical);
    pnl.add(Box.createHorizontalStrut(10));
    pnl.add(pnlSimulation);
    pnl.add(Box.createHorizontalStrut(10));
    pnl.add(pnlInvocation);
    add(pnl);
    
    //row 2
    pnl = getRowPanel();
    pnl.add(pnlQueryDateTime);
    pnl.add(Box.createHorizontalStrut(20));
    pnl.add(pnlQueryRegion);
    add(pnl);
    
    //row 3
    pnl = getRowPanel();
    pnl.add(pnlQueryOutput);
    pnl.add(Box.createHorizontalStrut(20));
    pnl.add(pnlQueryRun);
    add(pnl);
  }
  
//  public void setClockDateTime(long dateTime) {
//    clock.setDateTime(dateTime);
//  }
  
  public AbstractClock getClock() {
    return pnlQueryRun.getClock();
  }
  
  private JPanel getRowPanel() {
    JPanel pnl = new JPanel();
    pnl.setLayout(new BoxLayout(pnl, BoxLayout.LINE_AXIS));
    return pnl;
  }
  
  public void disableQueryControls() {
    pnlPhysical.disable();
    pnlQueryDateTime.disable();
    pnlQueryRegion.disable();
    pnlSimulation.disableControls();
  }
  
  public void enableQueryControls() {
    pnlPhysical.enable();
    pnlQueryDateTime.enable();
    pnlQueryRegion.enable();
    pnlSimulation.enableControls();
  }
    
}
